package com.asset.web;

import com.alibaba.fastjson.JSON;
import com.asset.service.AssetService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chart")
public class ChartController {

    @Resource
    private AssetService assetService;

    /**
     * 获取资产图表数据
     * @return
     */
    @PreAuthorize("hasRole('USER')")
    @GetMapping("/asset/{column}")
    public ResponseEntity<String> countByColumn(@PathVariable("column") String column) {
        List<Map<String, String>> list = assetService.countByColumn(column);
        String jsonString = JSON.toJSONString(list);
        return ResponseEntity.ok(jsonString);
    }
}
